#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>

#define N_MAX	100000
#define M_MAX	100000
#define COLOR_WHITE	0
#define COLOR_GRAY	1
#define COLOR_BLACK	2

struct Node {
	int x;
	Node *next;
};

struct adjlist {
	Node *first;
	Node *last;
	int size;

	short int visited;
	short int color;

	int index_in_path; //
};

static int path[N_MAX]; //values [0 ; N_MAX - 1]

static void
pushback(struct adjlist *al, int x)
{
	Node *newnode;

	newnode = (Node *) calloc(1, sizeof (Node));
	newnode->x = x;
	newnode->next = NULL;
	if (!al->first)
		al->first = newnode;
	else
		al->last->next = newnode;
	al->last = newnode;
	al->size++;
}

static void
free_al(struct adjlist *al)
{
	struct Node *n, *p;
	p = n = al->first;
	while (n) {
		n = n->next;
		free(p);
		p = n;
	}
}

static void
listprint(struct Node *node)
{
	while (node) {
		printf("%d%s", node->x + 1, node->next ? " -> " : "\n");
		node = node->next;
	}
}

static void
dfs_print_cycle(struct adjlist * const al, int cycle_st_node_idx, const int path_fin)
{
	register int i;
	for (i = cycle_st_node_idx; i <= path_fin; i++)
		(void) printf("%d ", path[i] + 1);
	(void) putchar('\n');
}

static short
dfs_find_cycles(struct adjlist * const al, const int start, const int path_idx)
{
	Node *node = NULL;
	short ret = -1;

	path[path_idx] = start;
	al[start].visited = 1;
	al[start].color = COLOR_GRAY;
	al[start].index_in_path = path_idx;
	node = al[start].first;

	while (node) {
		if (al[node->x].color == COLOR_GRAY) {
			puts("YES");
			dfs_print_cycle(al, al[node->x].index_in_path, path_idx);
			return (1);
		} else {
			ret = dfs_find_cycles(al, node->x, path_idx + 1);
			if (ret) return (ret);
		}

cont:
		node = node->next;
	}

	al[start].color = COLOR_BLACK;
	return (0);
}

int
main(void)
{
	static struct adjlist AL[N_MAX];
	char		line[1024];
	int		n, m;
	register int	i = 0;
	int		v_id, v_ref;
	int		ans = 0;

	(void) fgets(line, sizeof line / sizeof line[0], stdin);
	(void) sscanf(line, "%d %d", &n, &m);

	while (i < m) {
		(void) fgets(line, sizeof line / sizeof line[0], stdin);
		(void) sscanf(line, "%d %d", &v_id, &v_ref);
		pushback(&AL[v_id - 1], v_ref - 1);
		i++;
	}

	for (i = 0; i < n; i++)
		AL[i].visited = AL[i].color = 0;
	for (i = 0; i < n; i++)
		if (AL[i].visited == 0)
			if (ans = dfs_find_cycles(AL, i, 0))
				break;
	if (!ans) puts("NO");
out:
	for (i = 0; i < n; i++)
		free_al(&AL[i]);
	return (0);
}
